package com.origin.src.boot.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @RequestMapping("/")
    public String index() {
        return "SUCCESS";
    }


    @RequestMapping("/class")
    public String classLoader() {
        return this.getClass().getClassLoader().getName() + ":" + this.getClass().getClassLoader().getClass().getName();
    }


    @RequestMapping("/down")
    public String tests8(String a) throws InterruptedException {
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(300000);

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "okokokok-----------");
        }).start();

        Thread.sleep(20000);
        return a;
    }


    @RequestMapping("/test")
    public String test8(String a) {
        return a;
    }

    @RequestMapping("/test/1")
    public String test1(String a) {
        return a;
    }

    @RequestMapping("/test/{a}")
    public String testa(@PathVariable("a") String a) {
        return a;
    }

    @RequestMapping("/body")
//    @ResponseStatus(HttpStatus.SWITCHING_PROTOCOLS)
    public Object test(User user) {
        user = user == null ? new User() : user;
        return user;
//        return new ResponseEntity<>(user, HttpStatus.NOT_FOUND);
    }

    public static class User {
        String name = "username";
        String password = "password";

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }

}
